using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MicroMsg.UI.Page
{
	public class SelectPhoneContryPage : BasePage
	{
		public class Group<T> : List<T>
		{
			public string Key
			{
				get;
				set;
			}
			public bool HasItems
			{
				get
				{
					return 0 != base.get_Count();
				}
				set
				{
				}
			}
			public Group(string name, IEnumerable<T> items)
			{
				this.Key = name;
				using (IEnumerator<T> enumerator = items.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						T current = enumerator.get_Current();
						base.Add(current);
					}
				}
			}
			public override bool Equals(object value)
			{
				SelectPhoneContryPage.Group<T> group = value as SelectPhoneContryPage.Group<T>;
				return group != null && this.Key.Equals(group.Key);
			}
			public override int GetHashCode()
			{
				return base.GetHashCode();
			}
		}
		public static string sStrSelectedCountry;
		private DlgSelectCountry mDlgSelectCountry;
		private static List<SelectPhoneContryPage.Group<AreaCode>> sListAreas;
		private object mGroupHeaderLocker = new object();
		public bool sBIsSelectorShown;
		private ScrollViewer mScrollViewer;
		internal Grid LayoutRoot;
		internal StackPanel ContentPanel;
		internal panelTitleControl panel1Line;
		internal LongListSelector mListGroupAreas;
		private bool _contentLoaded;
		public SelectPhoneContryPage()
		{
			this.InitializeComponent();
			SelectPhoneContryPage.sStrSelectedCountry = null;
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && 2 == object_0.Length && object_0[0].GetType() == typeof(string))
			{
				if (object_0[1].GetType() == typeof(DlgSelectCountry))
				{
					this.regEventHandForList();
					SelectPhoneContryPage.sStrSelectedCountry = (object_0[0] as string);
					this.mDlgSelectCountry = (object_0[1] as DlgSelectCountry);
					if (this.mListGroupAreas.ItemsSource == null)
					{
						this.mListGroupAreas.ItemsSource = SelectPhoneContryPage.GetDataSource();
					}
					return;
				}
			}
		}
		protected override void OnPageOut()
		{
		}
		private void PhoneCountry_ItemClick(object sender, object object_0)
		{
			if (this.mDlgSelectCountry != null)
			{
				this.mDlgSelectCountry(SelectPhoneContryPage.sStrSelectedCountry);
			}
			base.GoBack();
		}
		public static List<SelectPhoneContryPage.Group<AreaCode>> GetDataSource()
		{
			if (SelectPhoneContryPage.sListAreas != null)
			{
				return SelectPhoneContryPage.sListAreas;
			}
			List<string> list = Enumerable.ToList<string>(strings.COM_CountryList.Split(new string[]
			{
				","
			}, 1));
			List<SelectPhoneContryPage.Group<AreaCode>> list2 = new List<SelectPhoneContryPage.Group<AreaCode>>();
			string text = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
			for (int i = 0; i < text.get_Length(); i++)
			{
				list2.Add(new SelectPhoneContryPage.Group<AreaCode>(text.get_Chars(i).ToString(), new List<AreaCode>()));
			}
			if (list != null)
			{
				using (List<string>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string current = enumerator.get_Current();
						AreaCode areaCode = AreaCode.createInstance(current);
						if (areaCode != null)
						{
							char c = areaCode.mStrOrderKey.Substring(0, 1).ToLower().get_Chars(0);
							int num = (int)(c - 'a' + '\u0001');
							if (num >= 1 && num < list2.get_Count() - 1)
							{
								list2.get_Item(num).Add(areaCode);
							}
						}
					}
				}
			}
			using (List<SelectPhoneContryPage.Group<AreaCode>>.Enumerator enumerator2 = list2.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					SelectPhoneContryPage.Group<AreaCode> current2 = enumerator2.get_Current();
					current2.Sort(new Comparison<AreaCode>(AreaCode.Compare));
				}
			}
			SelectPhoneContryPage.sListAreas = list2;
			return SelectPhoneContryPage.sListAreas;
		}
		public static AreaCode GetDefaultAreaCode()
		{
			List<SelectPhoneContryPage.Group<AreaCode>> dataSource = SelectPhoneContryPage.GetDataSource();
			if (dataSource == null)
			{
				return null;
			}
			RegionInfo currentRegion = RegionInfo.get_CurrentRegion();
			string twoLetterISORegionName = currentRegion.get_TwoLetterISORegionName();
			AreaCode result;
			using (List<SelectPhoneContryPage.Group<AreaCode>>.Enumerator enumerator = dataSource.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SelectPhoneContryPage.Group<AreaCode> current = enumerator.get_Current();
					if (current != null)
					{
						using (List<AreaCode>.Enumerator enumerator2 = current.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								AreaCode current2 = enumerator2.get_Current();
								if (twoLetterISORegionName == current2.mStrArea2WName)
								{
									result = current2;
									return result;
								}
							}
						}
					}
				}
				goto IL_8E;
			}
			return result;
			IL_8E:
			return null;
		}
		public static void ResetCountryList()
		{
			SelectPhoneContryPage.sListAreas = null;
		}
		private void GroupHeaderClick(object sender, object object_0)
		{
			this.ShownSelector();
		}
		public void ShownSelector()
		{
			lock (this.mGroupHeaderLocker)
			{
				if (this.sBIsSelectorShown)
				{
					return;
				}
				this.sBIsSelectorShown = true;
			}
			this.mListGroupAreas.DisplayGroupView();
		}
		private void mListGroupAreas_GroupViewOpened(object sender, GroupViewOpenedEventArgs e)
		{
			QuadraticEase quadraticEase = new QuadraticEase();
			quadraticEase.set_EasingMode(0);
			IEasingFunction easingFunction = quadraticEase;
			Storyboard storyboard = new Storyboard();
			ItemsControl itemsControl = e.ItemsControl;
			if (itemsControl == null)
			{
				return;
			}
			using (IEnumerator<object> enumerator = itemsControl.get_Items().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					object current = enumerator.get_Current();
					if (current != null)
					{
						UIElement uIElement = itemsControl.get_ItemContainerGenerator().ContainerFromItem(current) as UIElement;
						if (uIElement != null)
						{
							Border border = VisualTreeHelper.GetChild(uIElement, 0) as Border;
							if (border != null)
							{
								DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
								EasingDoubleKeyFrame easingDoubleKeyFrame = new EasingDoubleKeyFrame();
								easingDoubleKeyFrame.set_KeyTime(TimeSpan.FromMilliseconds(0.0));
								easingDoubleKeyFrame.set_Value(-90.0);
								easingDoubleKeyFrame.set_EasingFunction(easingFunction);
								EasingDoubleKeyFrame easingDoubleKeyFrame2 = new EasingDoubleKeyFrame();
								easingDoubleKeyFrame2.set_KeyTime(TimeSpan.FromMilliseconds(500.0));
								easingDoubleKeyFrame2.set_Value(0.0);
								easingDoubleKeyFrame2.set_EasingFunction(easingFunction);
								doubleAnimationUsingKeyFrames.get_KeyFrames().Add(easingDoubleKeyFrame);
								doubleAnimationUsingKeyFrames.get_KeyFrames().Add(easingDoubleKeyFrame2);
								Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath(PlaneProjection.RotationXProperty));
								Storyboard.SetTarget(doubleAnimationUsingKeyFrames, border.get_Projection());
								storyboard.get_Children().Add(doubleAnimationUsingKeyFrames);
							}
						}
					}
				}
			}
			storyboard.Begin();
		}
		private void mListGroupAreas_GroupViewClosing(object sender, GroupViewClosingEventArgs e)
		{
			e.Cancel = true;
			if (this.mListGroupAreas == null)
			{
				return;
			}
			this.mListGroupAreas.CloseGroupView();
			if (e.SelectedGroup != null)
			{
				if (this.mScrollViewer == null)
				{
					this.mListGroupAreas.ScrollToGroup(e.SelectedGroup);
				}
				else
				{
					SelectPhoneContryPage.Group<AreaCode> group = e.SelectedGroup as SelectPhoneContryPage.Group<AreaCode>;
					double num = 0.0;
					using (List<SelectPhoneContryPage.Group<AreaCode>>.Enumerator enumerator = SelectPhoneContryPage.sListAreas.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							SelectPhoneContryPage.Group<AreaCode> current = enumerator.get_Current();
							if (current.Key == group.Key)
							{
								break;
							}
							if (current.get_Count() != 0)
							{
								num += (double)(current.get_Count() + 1);
							}
						}
					}
					this.mScrollViewer.ScrollToVerticalOffset(num);
				}
			}
			this.sBIsSelectorShown = false;
		}
		private void regEventHandForList()
		{
			if (this.mScrollViewer != null)
			{
				return;
			}
			ScrollViewer scrollViewer = UIElementTraveler.FindElementRecursive(this.mListGroupAreas, typeof(ScrollViewer)) as ScrollViewer;
			this.mScrollViewer = scrollViewer;
			this.mListGroupAreas.ScrollingCompleted += new EventHandler(this.mListGroupAreas_ScrollingCompleted);
		}
		private void mListGroupAreas_ScrollingCompleted(object sender, EventArgs e)
		{
			if (this.mScrollViewer != null)
			{
				this.mScrollViewer.ScrollToVerticalOffset(this.mScrollViewer.get_VerticalOffset());
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/CommonUseControl/SelectPhoneContryPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.panel1Line = (panelTitleControl)base.FindName("panel1Line");
			this.mListGroupAreas = (LongListSelector)base.FindName("mListGroupAreas");
		}
	}
}
